<template>
  <p-echarts :option="option" />
</template>

<script>
import PEcharts from '@/components/charts/pEcharts'
import { postHandle } from '@/api'
export default {
  name: 'HjLine',
  components: { PEcharts },
  props: {
    geteWayCode: {
      type: String
    },
    obj: {
      type: Object
    }
  },
  data() {
    return {
      date: [],
      data1: [],
      data2: [],
      data3: [],
      data4: [],
      data5: [],
      data6: [],
      data7: [],
      data8: [],
      n: 0
    }
  },
  computed: {
    option() {
      return {
        grid: {
          left: 0,
          right: 5,
          bottom: 0,
          top: 15
        },
        xAxis: {
          type: 'category',
          axisTick: {
            show: false
          },
          axisLabel: {
            show: false
          },
          data: this.date
        },
        color: ['#5CD5C8', '#A48AEA', '#EAD18A', '#E07C71', '#8ED55C', '#D12A89',, '#fe2c24', '#999aaa'],
        yAxis: {
          max: 200,//最大值
          min: 0,//最小值
          splitLine: {
            lineStyle: {
              type: 'dashed',
              color: '#C2C2C2'
            }
          },
          axisLine: {
            show: false
          },
          axisTick: {
            show: false
          },
          axisLabel: {
            show: false
          },
          type: 'value'
        },
        series: [{
          name: '电流',
          data: this.data1,
          type: 'line',
          // smooth:true,    //拐弯处变锋利
          symbol: 'none', // 去除圆角
          sampling: 'average',
          animationDurationUpdate: 3000
        },
        {
          name: '电压',
          data: this.data2,
          type: 'line',
          // smooth:true,    //拐弯处变锋利
          symbol: 'none', // 去除圆角
          sampling: 'average',
          animationDurationUpdate: 3000
        },
        {
          name: '焊接速度(mm/秒)',
          data: this.data3,
          type: 'line',
          // smooth:true,    //拐弯处变锋利
          symbol: 'none', // 去除圆角
          sampling: 'average',
          animationDurationUpdate: 3000
        },
        {
          name: '层间温度(℃)',
          data: this.data4,
          type: 'line',
          // smooth:true,    //拐弯处变锋利
          symbol: 'none', // 去除圆角
          sampling: 'average',
          animationDurationUpdate: 3000
        },
        {
          name: '气流量',
          data: this.data5,
          type: 'line',
          // smooth:true,    //拐弯处变锋利
          symbol: 'none', // 去除圆角
          sampling: 'average',
          animationDurationUpdate: 3000
        },
        {
          name: '氩/C02',
          data: this.data6,
          type: 'line',
          // smooth:true,    //拐弯处变锋利
          symbol: 'none', // 去除圆角
          sampling: 'average',
          animationDurationUpdate: 3000
        },{
          name: '电流上限',
          data: this.data7,
          type: 'line',
          // smooth:true,    //拐弯处变锋利
          symbol: 'none', // 去除圆角
          sampling: 'average',
          animationDurationUpdate: 3000
        },{
          name: '电流下限',
          data: this.data8,
          type: 'line',
          // smooth:true,    //拐弯处变锋利
          symbol: 'none', // 去除圆角
          sampling: 'average',
          animationDurationUpdate: 3000
        }]
      }
    }
  },
  watch: {
    obj(val) {
      // let data = val.find(item => item.geteWay_code === this.geteWayCode)
      this.getData(val)
    }
  },
  mounted() {
    // let data = this.dataList.find(item => item.geteWay_code === this.geteWayCode)
    this.getData(this.obj)
  },
  methods: {
    getData(data) {
      if (this.date.length > 60) {
        this.date.shift()
        this.data1.shift()
        this.data2.shift()
        this.data3.shift()
        this.data4.shift()
        this.data5.shift()
        this.data6.shift()
      }
      if (data) {
        this.date.push(data['cjTime'])
        this.data1.push(data.current)
        this.data2.push(data.voltage)
        this.data3.push(data['ssSpeed'])
        this.data4.push(data['hazTemp'])
        this.data5.push(data['airFlux'])
        this.data6.push(data['arPurity'])
      } else {
        this.date.push(0)
        this.data1.push(0)
        this.data2.push(0)
        this.data3.push(0)
        this.data4.push(0)
        this.data5.push(0)
        this.data6.push(0)
      }
      // postHandle('/ekjdTest/api/HJDatas', { 'geteWay_code': [geteWayCode] }).then(res => {
      //   if (this.date.length > 60) {
      //     this.date.shift()
      //     this.data1.shift()
      //     this.data2.shift()
      //     this.data3.shift()
      //     this.data4.shift()
      //     this.data5.shift()
      //     this.data6.shift()
      //   }
      //   let data = res.result
      //   if (data && data.length > 0) {
      //     data.forEach((item, index) => {
      //       this.date.push(item['cj_time'])
      //       this.data1.push(item.current)
      //       this.data2.push(item.voltage)
      //       this.data3.push(item['ss_speed'])
      //       this.data4.push(item['haz_temp'])
      //       this.data5.push(item['air_flux'])
      //       this.data6.push(item['ar_purity'])
      //     })
      //   }
      // })
    }
  }
}
</script>

<style scoped>

</style>
